import { getAction, deleteAction, putAction, postAction, httpAction } from '@/api/manage'
import Vue from 'vue'
import {UI_CACHE_DB_DICT_DATA } from "@/store/mutation-types"

//角色管理
const addRole = (params)=>postAction("/platform/system/sysRole/add",params);
const editRole = (params)=>putAction("/platform/system/sysRole/edit",params);
const checkRoleCode = (params)=>getAction("/platform/system/sysRole/checkRoleCode",params);
const queryall = (params)=>getAction("/platform/system/sysRole/queryall",params);

//用户管理
const addUser = (params)=>postAction("/platform/system/sysUser/add",params);
const editUser = (params)=>putAction("/platform/system/sysUser/edit",params);
const queryUserRole = (params)=>getAction("/platform/system/sysUser/queryUserRole",params);
const getUserList = (params)=>getAction("/platform/system/sysUser/list",params);
const frozenBatch = (params)=>putAction("/platform/system/sysUser/frozenBatch",params);
//验证用户是否存在
const checkOnlyUser = (params)=>getAction("/platform/system/sysUser/checkOnlyUser",params);
//改变密码
const changePassword = (params)=>putAction("/platform/system/sysUser/changePassword",params);
//权限管理
const addPermission= (params)=>postAction("/platform/system/sysPermission/add",params);
const editPermission= (params)=>putAction("/platform/system/sysPermission/edit",params);
const getPermissionList = (params)=>getAction("/platform/system/sysPermission/list",params);
const getSystemMenuList = (params)=>getAction("/platform/system/sysPermission/getSystemMenuList",params);
const getSystemSubmenu = (params)=>getAction("/platform/system/sysPermission/getSystemSubmenu",params);
const getSystemSubmenuBatch = (params) => getAction('/platform/system/sysPermission/getSystemSubmenuBatch', params)

const queryTreeList = (params)=>getAction("/platform/system/sysPermission/queryTreeList",params);
const queryTreeListForRole = (params)=>getAction("/platform/system/sysRole/queryTreeList",params);
const queryListAsync = (params)=>getAction("/platform/system/sysPermission/queryListAsync",params);
const queryRolePermission = (params)=>getAction("/platform/system/sysPermission/queryRolePermission",params);
const saveRolePermission = (params)=>postAction("/platform/system/sysPermission/saveRolePermission",params);
const queryPermissionsByUser = ()=>getAction("/platform/system/sysPermission/getUserPermissionByToken");
const loadAllRoleIds = (params)=>getAction("/platform/system/sysPermission/loadAllRoleIds",params);
const getPermissionRuleList = (params)=>getAction("/platform/system/sysPermission/getPermRuleListByPermId",params);
const queryPermissionRule = (params)=>getAction("/platform/system/sysPermission/queryPermissionRule",params);

// 部门管理
const queryDepartTreeList = (params)=>getAction("/platform/system/sysDepart/queryTreeList",params);
const queryDepartByParams = (params)=>getAction("/platform/system/sysDepart/queryDepartByParams",params);
const queryDistrictTreeList = (params)=>getAction("/platform/system/sysDistrict/queryTreeList",params);
const queryIndustryTreeList = (params)=>getAction("/platform/system/sysIndustry/queryList",params);
const queryIdTree = (params)=>getAction("/platform/system/sysDepart/queryIdTree",params);
const queryParentName   = (params)=>getAction("/platform/system/sysDepart/queryParentName",params);
const searchByKeywords   = (params)=>getAction("/platform/system/sysDepart/searchBy",params);
const deleteByDepartId   = (params)=>deleteAction("/platform/system/sysDepart/delete",params);
const listDepartRoles = (params) => getAction('/platform/system/sysDepart/listDepartRoles', params);

//二级部门管理
const queryDepartPermission = (params)=>getAction("/platform/system/sysPermission/queryDepartPermission",params);
const saveDepartPermission = (params)=>postAction("/platform/system/sysPermission/saveDepartPermission",params);
const queryTreeListForDeptRole = (params)=>getAction("/platform/system/sysDepartPermission/queryTreeListForDeptRole",params);
const queryDeptRolePermission = (params)=>getAction("/platform/system/sysDepartPermission/queryDeptRolePermission",params);
const saveDeptRolePermission = (params)=>postAction("/platform/system/sysDepartPermission/saveDeptRolePermission",params);
const queryMyDepartTreeList = (params)=>getAction("/platform/system/sysDepart/queryMyDeptTreeList",params);

//日志管理
const deleteLog = (params)=>deleteAction("/platform/system/sysLog/delete",params);
const deleteLogList = (params)=>deleteAction("/platform/system/sysLog/deleteBatch",params);

//数据字典
const addDict = (params)=>postAction("/platform/system/sysDict/add",params);
const editDict = (params)=>putAction("/platform/system/sysDict/edit",params);
const treeList = (params)=>getAction("/platform/system/sysDict/treeList",params);
const addDictItem = (params)=>postAction("/platform/system/sysDictItem/add",params);
const editDictItem = (params)=>putAction("/platform/system/sysDictItem/edit",params);
const queryDictTreeList = (params)=>getAction("/platform/system/sysDict/queryDictTreeList",params);
const deleteByDictId = (params)=>deleteAction("/platform/system/sysDict/delete",params);
const queryDictIdTree = (params)=>getAction("/platform/system/sysDict/queryDictIdTree",params);
const queryDictItemTreeList = (params)=>getAction("/platform/system/sysDictItem/queryDictItemTreeList",params);
const queryDictItemIdTree = (params)=>getAction("/platform/system/sysDictItem/queryDictItemIdTree",params);
const deleteByDictItemId = (params)=>deleteAction("/platform/system/sysDictItem/delete",params);

//字典标签专用（通过code获取字典数组）
export const ajaxGetDictItems = (code, params)=>getAction(`/platform/system/sysDict/getDictItems/${code}`,params);
//从缓存中获取字典配置
function getDictItemsFromCache(dictCode) {
  if (Vue.ls.get(UI_CACHE_DB_DICT_DATA) && Vue.ls.get(UI_CACHE_DB_DICT_DATA)[dictCode]) {
    let dictItems = Vue.ls.get(UI_CACHE_DB_DICT_DATA)[dictCode];
    console.log("-----------getDictItemsFromCache----------dictCode="+dictCode+"---- dictItems=",dictItems)
    return dictItems;
  }
}

//系统通告
const doReleaseData = (params)=>getAction("/platform/message/sysAnnouncement/doReleaseData",params);
const doReovkeData = (params)=>getAction("/platform/message/sysAnnouncement/doReovkeData",params);
//获取系统访问量
const getLoginfo = (params)=>getAction("/sys/loginfo",params);
const getVisitInfo = (params)=>getAction("/sys/visitInfo",params);
// 根据部门主键查询用户信息
const queryUserByDepId = (params)=>getAction("/platform/system/sysUser/queryUserByDepId",params);
// 重复校验
const duplicateCheck = (params)=>getAction("/platform/system/duplicate/check",params);
const duplicateDictItemCheck = (params)=>postAction("/platform/system/duplicate/dictItemCheck", params)
// 加载分类字典
const loadCategoryData = (params)=>getAction("/platform/system/sysCategory/loadAllData",params);
const checkRuleByCode = (params) => getAction('/platform/system/sysCheckRule/checkByCode', params)
//加载我的通告信息
const getUserNoticeInfo= (params)=>getAction("/platform/message/sysAnnouncementSend/getMyAnnouncementSend",params);
const getTransitURL = url => `/sys/common/transitRESTful?url=${encodeURIComponent(url)}`
// 中转HTTP请求
export const transitRESTful = {
  get: (url, parameter) => getAction(getTransitURL(url), parameter),
  post: (url, parameter) => postAction(getTransitURL(url), parameter),
  put: (url, parameter) => putAction(getTransitURL(url), parameter),
  http: (url, parameter) => httpAction(getTransitURL(url), parameter),
}

//表单管理
const getBpmForm = (params)=>getAction("/base/bpm/form/queryById",params);
const addBpmForm = (params)=>postAction("/base/bpm/form/add",params);
const editBpmForm = (params)=>putAction("/base/bpm/form/edit",params);
const copyBpmForm = (params)=>putAction("/base/bpm/form/copy",params);
const saveBpmFormDesign = (params)=>putAction("/base/bpm/form/saveDesign",params);
const publishBpmForm = (params)=>putAction("/base/bpm/form/publish",params);
const getTableFields = (params)=>getAction("/base/bpm/form/getTableFields",params);
const getBpmFormData = (params)=>getAction("/base/bpm/form/getFormData",params);
const getTableFieldTree = (params)=>getAction("/base/bpm/form/getTableFieldTree",params);

const getBpmTable = (params)=>getAction("/base/bpm/table/queryById",params);
const addBpmTable = (params)=>postAction("/base/bpm/table/add",params);
const editBpmTable = (params)=>putAction("/base/bpm/table/edit",params);
const createBpmTable = (params)=>putAction("/base/bpm/table/create",params);

const editBpmProcType = (params) => postAction("/activiti/models/editProcType", params)

// 系统基本信息管理
const getSysBaseInfo = (params) => getAction("/sys/baseInfo/queryById", params);
const changeSysBaseInfo = (params) => putAction("/sys/baseInfo/save", params);

// 系统安全信息管理
const getSysSecurityInfo = (params) => getAction("/sys/securityInfo/queryById", params);
const changeSysSecurityInfo = (params) => putAction("/sys/securityInfo/save", params);

const getCurrLoginUserInfo = (params) => getAction("/platform/system/sysUser/getCurrLoginUserInfo");
const getCurrSysUserInfo = (params) => getAction("/platform/system/sysUser/getCurrSysUserInfo");
const changeSysUserInfo = (params) => putAction("/platform/system/sysUser/changeSysUserInfo", params);

const saveGoodThingsVerify = (params) => postAction("/goodThings/verify", params);
const saveMinorProtectVerify = (params) => postAction("/minorProtect/verify", params);
const getCount = () => getAction("/goodThings/getCount");
const getGoodThingsGraph = (params) => postAction("/goodThings/getCurveGraph", params);
const getMinorProtectGraph = (params) => postAction("/minorProtect/getCurveGraph", params);
const getPieGraph = (params) => getAction("/minorProtect/getPieGraph", params);
const getColGraph = (params) => getAction("/minorProtect/getColGraph", params);

export {
  queryDepartByParams,
  addRole,
  editRole,
  checkRoleCode,
  addUser,
  queryDistrictTreeList,
  queryIndustryTreeList,
  editUser,
  queryUserRole,
  getUserList,
  queryall,
  frozenBatch,
  checkOnlyUser,
  changePassword,
  getPermissionList,
  addPermission,
  editPermission,
  queryTreeList,
  queryListAsync,
  queryRolePermission,
  saveRolePermission,
  queryPermissionsByUser,
  loadAllRoleIds,
  getPermissionRuleList,
  queryPermissionRule,
  queryDepartTreeList,
  queryIdTree,
  queryParentName,
  searchByKeywords,
  deleteByDepartId,
  deleteLog,
  deleteLogList,
  addDict,
  editDict,
  treeList,
  queryDictTreeList,
  queryDictIdTree,
  queryDictItemTreeList,
  queryDictItemIdTree,
  deleteByDictItemId,
  deleteByDictId,
  addDictItem,
  editDictItem,
  doReleaseData,
  doReovkeData,
  getLoginfo,
  getVisitInfo,
  queryUserByDepId,
  duplicateCheck,
  queryTreeListForRole,
  getSystemMenuList,
  getSystemSubmenu,
  getSystemSubmenuBatch,
  loadCategoryData,
  checkRuleByCode,
  queryDepartPermission,
  saveDepartPermission,
  queryTreeListForDeptRole,
  queryDeptRolePermission,
  saveDeptRolePermission,
  queryMyDepartTreeList,
  getUserNoticeInfo,
  getDictItemsFromCache,
  getBpmForm,
  addBpmForm,
  editBpmForm,
  copyBpmForm,
  saveBpmFormDesign,
  publishBpmForm,
  getTableFields,
  getTableFieldTree,
  getBpmFormData,
  getBpmTable,
  addBpmTable,
  editBpmTable,
  createBpmTable,
  listDepartRoles,
  duplicateDictItemCheck,
  editBpmProcType,
  getSysBaseInfo,
  changeSysBaseInfo,
  getSysSecurityInfo,
  changeSysSecurityInfo,
  getCurrLoginUserInfo,
  getCurrSysUserInfo,
  changeSysUserInfo,
  saveGoodThingsVerify,
  saveMinorProtectVerify,
  getCount,
  getGoodThingsGraph,
  getMinorProtectGraph,
  getPieGraph,
  getColGraph,

}



